﻿using System.Collections.Generic;
using System.Web.Mvc;
using System;
using System.Linq;

namespace RMH.Web.Exensions
{
public static class EnumExtensions
{
    public static IEnumerable<SelectListItem> ToSelectList(this Enum items)
    {
        List<SelectListItem> tmpRtn = new List<SelectListItem>();

        Type t = items.GetType();
        IEnumerable<int> values = Enum.GetValues(t).Cast<int>();

        foreach (var item in values)
        {
            tmpRtn.Add(new SelectListItem() { Value = item.ToString(), Text = Enum.GetName(t,item) });
        }

        return tmpRtn.Cast<SelectListItem>();
    }
}
}